package demo;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardDemo {
    private String[] colors = {"♥","♦","♣","♠"};
    private int[] nums = {1,2,3,4,5,6,7,8,9,10,11,12,13};
    private List<Card> cards = new ArrayList<>();
    public void buyCard(){
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 13; j++) {
                Card card = new Card(colors[i],nums[j]);
                cards.add(card);
            }
        }
        System.out.println(cards);
    }

    public void washCard(){
        Random random = new Random();
        int i = 51;
        while(i > 0){
            int j = random.nextInt(i );
            swap(cards,i,j);
            i--;
        }
        System.out.println(cards);
    }

    private void swap(List<Card> cards,int a,int b){
        Card tmp = cards.get(a) ;
        cards.set(a,cards.get(b));
        cards.set(b,tmp);

    }


    public void play(){
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();
        List<List<Card>> hands = new ArrayList<>();
        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cards.remove(0);
                hands.get(j).add(card);
            }
        }
        System.out.println("第一个人摸到的牌");
        System.out.println(hand1);
        System.out.println("第二个人摸到的牌");
        System.out.println(hand2);
        System.out.println("第三个人摸到的牌");
        System.out.println(hand3);
        System.out.println("剩下的牌");
        System.out.println(hands);
    }
}
